#!/usr/bin/env bash

PACKAGE_NAME="$1"
PACKAGE_VERSION="$2"

if [ "$PACKAGE_NAME" = "" ]; then
    PACKAGE_NAME=flowfe
fi
if [ "$PACKAGE_VERSION" = "" ]; then
    PACKAGE_VERSION=latest
fi

targetimage="${PACKAGE_NAME}:${PACKAGE_VERSION}"

docker stop "${PACKAGE_NAME}-test"
docker rm -f "${PACKAGE_NAME}-test"


if [[ `uname` == 'Darwin' ]]; then
    echo "Mac OS"
    METHOD='-p 8000:8000 -p 8001:8001 -p 80:80'
elif [[ `uname` == 'Linux' ]]; then
    echo "Linux"
    METHOD='--net=host'
fi

# 注意如果是Mac，还需要修改 docker/nginx/conf.d/default.conf下的proxy_pass为宿主机IP
docker run \
-d ${METHOD} -P \
--name "${PACKAGE_NAME}-test" \
$targetimage
